package com.hstx.demo.mqtt.until;

import org.slf4j.LoggerFactory;

public class Log {

    public static void trace(Class<?> clazz, String msg) {
        LoggerFactory.getLogger(clazz).trace(msg);
    }

    public static void trace(Class<?> clazz, Exception e) {
        if(e != null) {
            trace(clazz, e.toString());
            StackTraceElement[] stackTraceElements = e.getStackTrace();
            int steNums = stackTraceElements.length;
            for(int i = 0; i < steNums; i++) {
                trace(clazz, stackTraceElements[i].toString());
            }
        }
    }

    public static void trace(Class<?> clazz, Exception e, String ...traceMsg) {
        int len = traceMsg.length;
        for (int i = 0; i < len; i++) {
            trace(clazz, traceMsg[i]);
        }
        trace(clazz, e);
    }

    public static void debug(Class<?> clazz, String msg) {
        LoggerFactory.getLogger(clazz).debug(msg);
    }

    public static void debug(Class<?> clazz, Exception e) {
        if(e != null) {
            debug(clazz, e.toString());
            StackTraceElement[] stackTraceElements = e.getStackTrace();
            int steNums = stackTraceElements.length;
            for(int i = 0; i < steNums; i++) {
                debug(clazz, stackTraceElements[i].toString());
            }
        }
    }

    public static void debug(Class<?> clazz, Exception e, String ...debugMsg) {
        int len = debugMsg.length;
        for (int i = 0; i < len; i++) {
            debug(clazz, debugMsg[i]);
        }
        debug(clazz, e);
    }

    public static void info(Class<?> clazz, String msg) {
        LoggerFactory.getLogger(clazz).info(msg);
    }

    public static void info(Class<?> clazz, Exception e) {
        if(e != null) {
            info(clazz, e.toString());
            StackTraceElement[] stackTraceElements = e.getStackTrace();
            int steNums = stackTraceElements.length;
            for(int i = 0; i < steNums; i++) {
                info(clazz, stackTraceElements[i].toString());
            }
        }
    }

    public static void info(Class<?> clazz, Exception e, String ...infoMsg) {
        int len = infoMsg.length;
        for (int i = 0; i < len; i++) {
            info(clazz, infoMsg[i]);
        }
        info(clazz, e);
    }

    public static void warn(Class<?> clazz, String msg) {
        LoggerFactory.getLogger(clazz).warn(msg);
    }

    public static void warn(Class<?> clazz, Exception e) {
        if(e != null) {
            warn(clazz, e.toString());
            StackTraceElement[] stackTraceElements = e.getStackTrace();
            int steNums = stackTraceElements.length;
            for(int i = 0; i < steNums; i++) {
                warn(clazz, stackTraceElements[i].toString());
            }
        }
    }

    public static void warn(Class<?> clazz, Exception e, String ...warnMsg) {
        int len = warnMsg.length;
        for (int i = 0; i < len; i++) {
            warn(clazz, warnMsg[i]);
        }
        warn(clazz, e);
    }

    public static void error(Class<?> clazz, String msg) {
        LoggerFactory.getLogger(clazz).error(msg);
    }

    public static void error(Class<?> clazz, Exception e) {
        if (e != null) {
            error(clazz, e.toString());
            StackTraceElement[] stackTraceElements = e.getStackTrace();
            int steNums = stackTraceElements.length;
            for(int i = 0; i < steNums; i++) {
                error(clazz, stackTraceElements[i].toString());
            }
        }
    }

    public static void error(Class<?> clazz, Exception e, String ...errorMsg) {
        int len = errorMsg.length;
        for (int i = 0; i < len; i++) {
            error(clazz, errorMsg[i]);
        }
        error(clazz, e);
    }
}
